package com.cskaoyan.controller;


import com.cskaoyan.bean.baseresultVO.BaseData;
import com.cskaoyan.bean.baseresultVO.BaseParam;
import com.cskaoyan.bean.baseresultVO.BaseRespVo;
import com.cskaoyan.bean.domain.Coupon;
import com.cskaoyan.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.BindingResult;

import javax.validation.Valid;

/**
 * <p>
 * 优惠券信息及规则表 前端控制器
 * </p>
 *
 * @author zhiMing
 * @since 2021年11月30日
 */
@RestController
@RequestMapping("/admin/coupon")
public class CouponController {
    @Autowired
    CouponService couponService;

    @GetMapping("list")
    public BaseRespVo<BaseData> couponList(String name, Short type, Short status, BaseParam baseParam) {
        BaseData baseData = couponService.couponList(name, type, status, baseParam);
        return BaseRespVo.ok(baseData);
    }

    @GetMapping("read")
    public BaseRespVo<Coupon> couponRead(Integer id) {
        Coupon coupons = couponService.couponRead(id);
        return BaseRespVo.ok(coupons);
    }

    @GetMapping("listuser")
    public BaseRespVo<BaseData> listUser(Integer couponId, Integer userId, Short status, BaseParam baseParam) {
        BaseData baseData = couponService.listUser(couponId, userId, status, baseParam);
        return BaseRespVo.ok(baseData);
    }

    @PostMapping("update")
    public BaseRespVo<Coupon> couponUpdate(@RequestBody @Valid Coupon coupon) {
        Coupon coupon1 = couponService.couponUpdate(coupon);
        return BaseRespVo.ok(coupon1);
    }

    @PostMapping("delete")
    public BaseRespVo couponDelete(@RequestBody Coupon coupon) {
        int affectedRow = couponService.couponDelete(coupon);
        return BaseRespVo.ok(affectedRow);
    }

    @PostMapping("create")
    public BaseRespVo<Coupon> couponCreate(@RequestBody @Valid Coupon coupon) {
        Coupon coupon1 = couponService.couponCreate(coupon);
        return BaseRespVo.ok(coupon1);
    }
}

